package com.zl.gmadmin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zl.gmadmin.common.ApiResponse;
import com.zl.gmadmin.payload.WorkflowQueryCriteria;
import com.zl.gmadmin.service.WorkflowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: ZhangLiang
 * @Date: 2021/09/04/10:47
 * @Description:
 */
@Api("工作流")
@RestController
@RequestMapping("/api/unit/workflow")
public class WorkflowController {

    private final WorkflowService workflowService;

    public WorkflowController(WorkflowService workflowService) {
        this.workflowService = workflowService;
    }


    @ApiOperation("分页获取工作流定义")
    @GetMapping
    public ApiResponse selectPageVo(WorkflowQueryCriteria queryCriteria, Page page) {
        // 工作流

        return ApiResponse.ofSuccess(workflowService.selectPageVo(queryCriteria, page));
    }

    /**
     * 获取工作流程定义资源xml
     *
     * @param deploymentId
     * @param resourceName
     * @param response
     */
    @ApiOperation("获取流程")
    @GetMapping("processResources")
    public void getProcessResources(String deploymentId, String resourceName, HttpServletResponse response) {
        workflowService.getProcessResources(deploymentId, resourceName, response);
    }


    @ApiOperation("新增流程")
    @PostMapping
    public ApiResponse addBPMNAndDeployment(@RequestBody WorkflowQueryCriteria addXMLRequest) {
        System.out.println("增加");
        System.out.println(addXMLRequest.getName()+":"+addXMLRequest.getXml());
        workflowService.addBPMNAndDeployment(addXMLRequest);
        return ApiResponse.ofSuccess();
    }

    @ApiOperation("更新流程信息")
    @PutMapping
    public  ApiResponse updateBPMNAndDeployment(){
        workflowService.updateBPMNAndDeployment();
        return  ApiResponse.ofSuccess();
    }
    @ApiOperation("删除流程")
    @DeleteMapping
    public ApiResponse delBPMNAndDeployment(@RequestBody List<String> ids){
        workflowService.delBPMNAndDeployment(ids);
        return  ApiResponse.ofSuccess();
    }
}
